

	
use Data/Estimation_sample.dta, clear
	
	gen nexis_buildings  = ROOFME/PROOFME
		
		
	gen roofratio = ROOFME/ROOFTI
	gen roofratiobuildings = roofratio*nexis_buildings
		
	gen roofrelativeIV = (roofratio*nexis_buildings/[moduleprice])/1000

	
	
	label variable roofrelativeIV "Relative Roof Instrument"
	
	
	label variable TotalHouse "Dwellings (000)"
	label variable median_income "Median Income (000/week)"
	label variable median_age "Median Age"
	label variable PSeparate "Proportion Separate Dwellings"
	label variable median_rooms "Median House Size"
	label variable PFullTime "Proportion Employed Full Time"
	label variable median_mortgage "Median Mortgage Payment (000/month)"
	label variable median_rent "Median Rental Payment (000/week)"
	label variable PBachelor "Proportion Bachelor Degree"
	label variable PRented "Proportion Rental Property"

	
	
	
	xi: xtivreg2 cuminst roofrelativeIV  i.quarter  [aweight =NCustomers	], fe cluster(postcode)

	
	
	
	quietly summ cuminst [aweight =NCustomers	] if e(sample)
    local meandepvar=round(`r(mean)',.001)
	
		outreg2 using Analysis/First_stageIV.tex, bdec(3) label ///
	keep(roof*) ctitle(" ") addtext(Postcode FE, Yes, Year-Quarter FE, Yes, Mean dep var, 0`meandepvar') ///
	tex(fragment pretty) nonotes replace
	
	
	
	
	
	
	xi: xtivreg2 cuminst roofrelativeIV median_income_interp median_mortgage_interp PBachelor_interp PFullTime_interp  i.quarter  [aweight =NCustomers	] , fe cluster(postcode) 
	
	
	
	
	quietly summ cuminst [aweight =NCustomers	] if e(sample)
    local meandepvar=round(`r(mean)',.001)
	
	
		outreg2 using Analysis/First_stageIV.tex, bdec(3) label ///
	keep(roof* median* P*)  ctitle(" ")  addtext(Postcode FE, Yes, Year-Quarter FE, Yes, Mean dep var, 0`meandepvar') ///
	tex(fragment pretty) nonotes append
	

	
	
	**** region by year FEs	
	
	
	merge m:1 postcode using Data/SA3postcode.dta
	
	keep if _merge ==3
	drop _merge 
	gen SA3_year =  SA3 + string(year)
	
	quietly tab SA3_year, gen(SA3yearFE)
	
	
	
	
	xi: xtivreg2 cuminst roofrelativeIV median_income_interp median_mortgage_interp PBachelor_interp PFullTime_interp  i.quarter SA3yearFE* [aweight =NCustomers] , fe cluster(postcode) partial(SA3yearFE*)
	
	
	
	
	quietly summ cuminst [aweight =NCustomers	] if e(sample)
    local meandepvar=round(`r(mean)',.001)
	
	
		outreg2 using Analysis/First_stageIV.tex, bdec(3) label ///
	keep(roof* median* P*) ctitle(" ") addtext(Postcode FE, Yes, Year-Quarter FE, Yes, Mean dep var, 0`meandepvar') ///
	tex(fragment pretty) nonotes append
	
	
	
	
		**** roofratio  by year FEs

	
	merge m:1 postcode using Data/AboveBelowRoof.dta

	drop _merge

	merge m:1 postcode using Data/Postcode_matching.dta

	drop _merge 

	
	merge m:1 postcode using Data/SA3postcode.dta
	drop _merge
	merge m:1 SA3_CODE16 using "data/maps/sa3" 

	
	drop _merge
	*  melbourne

	gen Melbourne = 1 if SA4_CODE=="213" | SA4_CODE =="210" | SA4_CODE=="209" | SA4_CODE =="207" | SA4_CODE=="211"  | SA4_CODE=="208" | 	SA4_CODE=="206" | SA4_CODE=="212"
	replace Melbourne =0 if Melbourne ==.`'
				

	gen notinner25 = (Melbourne ==1 )*(GPO_distance>2.5)
	gen notinner5 = (Melbourne ==1 )*(GPO_distance>5)
	gen notinner75 = (Melbourne ==1 )*(GPO_distance>7.5)
	gen notinner10 = (Melbourne ==1 )*(GPO_distance>10)
				
				
			forvalues y = 2009(1)2015 { 
						forval q = 1(1)5{ 

			gen quin_year`y'_`q' = (year==`y')*(quintiles_Relative==`q')  
						}
			gen distance_year`y' = GPO_distance * year==`y'
 			gen above_med_`y' = (above_medRelative==2) * (year==`y')

			foreach var in 25 5 75 10 {
				gen notinneryear`var'_`y' = notinner`var'* (year==`y')
			
			
			}
			
					}
		
		
		
	
	
	xi: xtivreg2 cuminst roofrelativeIV median_income_interp median_mortgage_interp PBachelor_interp PFullTime_interp  i.quarter distance_year* [aweight =NCustomers	] , fe cluster(postcode) partial(distance_year*)
	
	
	
	
	quietly summ cuminst [aweight =NCustomers	] if e(sample)
    local meandepvar=round(`r(mean)',.001)
	
	
		outreg2 using Analysis/First_stageIV.tex, bdec(3) label ///
	keep(roof* median* P*) ctitle(" ") addtext(Postcode FE, Yes, Year-Quarter FE, Yes, Mean dep var, 0`meandepvar') ///
	tex(fragment pretty) nonotes append
	
	
	
	
	xi: xtivreg2 cuminst roofrelativeIV median_income_interp median_mortgage_interp PBachelor_interp PFullTime_interp  i.quarter above_med_* [aweight =NCustomers	] , fe cluster(postcode) partial(above_med_*)
	
	
	
	
	quietly summ cuminst [aweight =NCustomers	] if e(sample)
    local meandepvar=round(`r(mean)',.001)
	
	
		outreg2 using Analysis/First_stageIV.tex, bdec(3) label ///
	keep(roof* median* P*) ctitle(" ") addtext(Postcode FE, Yes, Year-Quarter FE, Yes, Mean dep var, 0`meandepvar') ///
	tex(fragment pretty) nonotes append
	

	
	
	
	
	
	xi: xtivreg2 cuminst roofrelativeIV median_income_interp median_mortgage_interp PBachelor_interp PFullTime_interp  i.quarter quin_year* [aweight =NCustomers	] , fe cluster(postcode) partial(quin_year*)
	
	
	
	
	quietly summ cuminst [aweight =NCustomers	] if e(sample)
    local meandepvar=round(`r(mean)',.001)
	
	
		outreg2 using Analysis/First_stageIV.tex, bdec(3) label ///
	keep(roof* median* P*) ctitle(" ") addtext(Postcode FE, Yes, Year-Quarter FE, Yes, Mean dep var, 0`meandepvar') ///
	tex(fragment pretty) nonotes append
	

	
	
	
	
	
	
	
	
	
	merge m:1 postcode using Data/Census2006postcode.dta
	
	drop if _merge ==2
	drop _merge
	
	
 
 
	
	xi: ivreghdfe  cuminst roofrelativeIV  [aweight =NCustomers] , absorb(postcode quarter c.median_income#i.year c.median_mortgage#i.year c.PBachelor#i.year c.PFullTime#i.year ) cluster(postcode) 
	

	
	quietly summ cuminst [aweight =NCustomers	] if e(sample)
    local meandepvar=round(`r(mean)',.001)
	
	
		outreg2 using Analysis/First_stageIV.tex, bdec(3) label ///
	keep(roof* median* P*) ctitle(" ") addtext(Postcode FE, Yes, Year-Quarter FE, Yes, Mean dep var, 0`meandepvar') ///
	tex(fragment pretty) nonotes append
	

